package com.session03.homework;

import java.util.ArrayList;
import java.util.List;

public class StudentList {
    //设计一个学生类：姓名、年龄、分数三个属性。
    // 输入5个学生的信息，放入到一个List集合，然后对这个List中的5个学生按成绩进行从大到小排序；
    public static void main(String[] args) {
        List<Student> list = new ArrayList();

        list.add(new Student("张三", 18, 80));
        list.add(new Student("李四", 19, 90));
        list.add(new Student("王五", 20, 75));
        list.add(new Student("赵六", 21, 85));
        list.add(new Student("彭七", 22, 78));

        //System.out.println(list.get(0).getScore());

        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = 0; j < list.size() - 1 - i; j++) {
                if (list.get(j).getScore() < list.get(j + 1).getScore()) {
                    Student stu1 = new Student();
                    Student stu2 = new Student();
                    stu1 = list.get(j);
                    stu2 = list.get(j + 1);
                    list.set(j, stu2);
                    list.set(j + 1, stu1);
                }
            }
        }

        for (Student student : list) {
            System.out.println(student);
        }
    }
}
